package com.wzl.customviewproject.util;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;

import com.wzl.customviewproject.R;

import java.util.List;

/**
 * 作者：longxiansen
 * 功能：STEP2:动态添加数据.核心就是一个addView方法
 */
public class DataFlowLayout extends FlowLayout{
    public DataFlowLayout(Context context) {
        super(context);
    }

    public DataFlowLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DataFlowLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setData(List<String> datas){
        for (int i = 0; i < datas.size(); i++) {
            TextView textView = new TextView(getContext());
            textView.setText(datas.get(i));
            textView.setPadding(dp2px(10),dp2px(5),dp2px(10),dp2px(5));
            textView.setBackgroundResource(R.drawable.bg_yellow);
            addView(textView);
        }
        postInvalidate();
    }
}
